﻿$(document).ready(function () {
    $('.btn').on('click', function () {
        switch ($(this).text()) {
            case "注册":
                window.document.location.href = "/register";
                break;
            case "登入":
                var data = {
                    _csrf: $("meta[name=x-csrf-token]").attr("content"),
                    user: $("input[name='username']").val(),
                    psw: $("input[name='password']").val()
                }
                $.post('/login', data, function (data, status) {
                    var data_obj = JSON.parse(data);
                    if (data_obj["code"] == "200") {
                        window.document.location.href = data_obj["url"];
                        sessionStorage.clear();
                    } else {
                        showModal("登入失败", "错误信息:" + data_obj["data"] + "\t内部错误代码：" + data_obj["code"]);
                    }
                }).error(function (jxr, status, msg) {
                    showModal("系统错误", "错误信息:<" + jxr.status + ">" + msg);
                });
                break;
        }
    })
});